/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com 

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "rectangle.h"


namespace tri {

std::ostream &operator<<(std::ostream& out, const tri::TRectangle& m) {
    
    out<<m.toString()<<std::endl;
    return out;
}


TRectangle::TRectangle(float left, float top, float right, float bottom) : TObject(){
    value[0]=left;
    value[1]=top;
    value[2]=right;
    value[3]=bottom;
}

TRectangle::TRectangle(float v[4]) : TObject() {
    value[0]=v[0];
    value[1]=v[1];
    value[2]=v[2];
    value[3]=v[3];
}
TRectangle::~TRectangle() {
}

std::string TRectangle::toString() const{
	std::string out;
	out += "TRectangle: ";
    for (int i = 0; i<4; i++) {
        out += " " + utils::float2String(value[i]);
    }
    return out;
}

void TRectangle::get(float v[4]) {
    v[0] = value[0];
    v[1] = value[1];
    v[2] = value[2];
    v[3] = value[3];
}

const float* TRectangle::getValue() {
    return value;
}

void TRectangle::setValue(float left, float top, float right, float bottom) {
    value[0]=left;
    value[1]=top;
    value[2]=right;
    value[3]=bottom;
}

void TRectangle::setValue(TRectangle* r){
	value[0] = r->value[0];
	value[1] = r->value[1];
	value[2] = r->value[2];
	value[3] = r->value[3];
}

void TRectangle::getRectValue(float v[8]) {
    v[0] = value[0];
    v[1] = value[1];

    v[2] = value[2];
    v[3] = value[1];

    v[4] = value[0];
    v[5] = value[3];

    v[6] = value[2];
    v[7] = value[3];
}

TRectangle TRectangle::copy() {
    float v[4];
    this->get(v);
    return TRectangle(v[0], v[1], v[2], v[3]);
}

//TRectangle TRectangle::getSubRectangle(TRectangle &rect){
//    const float * v = rect.getValue();
//    
//    TRectangle rect(l*v[0]);
//}
void TRectangle::translate(float x, float y) {
    value[0]+=x;
    value[1]+=y;
    value[2]+=x;
    value[3]+=y;
}

float TRectangle::getTop(){
	return value[1];
}
	
void TRectangle::setTop(float f){
	value[1] = f;
}

float TRectangle::getLeft(){
	return value[0];
}

void TRectangle::setLeft(float f){
	value[0] = f;
}

float TRectangle::getRight(){
	return value[2];
}

void TRectangle::setRight(float f){
	value[2] = f;
}

float TRectangle::getBottom(){
	return value[3];
}

void TRectangle::setBottom(float f){
	value[3] = f;
}

}

